package com.baizhi.shane.shane.controller;

import com.baizhi.shane.common.base.Result;
import com.baizhi.shane.constant.ApiMapping;
import com.baizhi.shane.constant.TableNameMapping;
import com.baizhi.shane.shane.entity.ShaneCommentEssay;
import com.baizhi.shane.shane.entity.ShaneCommentQuestion;
import com.baizhi.shane.shane.entity.ShaneEssay;
import com.baizhi.shane.shane.entity.ShaneQuestion;
import com.baizhi.shane.shane.service.*;
import com.baizhi.shane.shane.vo.*;
import com.baizhi.shane.sys.vo.IdVO;
import com.baizhi.shane.sys.vo.SuccessedOutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 闻柏智
 * @date 2023/09/20 21:44:21
 */
@RestController
@RequestMapping(TableNameMapping.SHANE_ESSAY)
@Api(tags="文章表")
public class ShaneEssayController {
    @Resource
    private ShaneEssayService shaneEssayService;
    @Resource
    private ShaneLikesEssayService shaneLikesEssayService;
    @Resource
    private ShaneCollectEssayService shaneCollectEssayService;
    @Resource
    private ShaneAgainstEssayService shaneAgainstEssayService;
    @Resource
    private ShaneCommentEssayService shaneCommentEssayService;

    /**
     * 新增一个文章
     *
     * @Author 闻柏智
     * @Date 16:27 2024/3/2
     * @Param essayInsertInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="新增一个文章", notes="新增一个文章")
    @PostMapping(value = ApiMapping.INSERT_ONE)
    public Result<SuccessedOutVO> insertOne(
            @RequestBody EssayInsertInVO essayInsertInVO
    ) {
        SuccessedOutVO successedOutVO = shaneEssayService.insertOne(essayInsertInVO);
        return Result.OK(successedOutVO);
    }

    /**
     * 查询单个文章-原生
     *
     * @Author 闻柏智
     * @Date 22:41 2024/3/3
     * @Param essayId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.entity.ShaneEssay>
     **/
    @ApiOperation(value="查询单个文章-原生", notes="查询单个文章-原生")
    @GetMapping(value = ApiMapping.GET_ONE_ORIGIN)
    public Result<ShaneEssay> getOneOrigin(
            @RequestParam("essayId") @ApiParam("问题ID") Long essayId
    ) {
        ShaneEssay shaneEssay = shaneEssayService.getById(essayId);
        return Result.OK(shaneEssay);
    }

    /**
     * 通过ID编辑文章
     *
     * @Author 闻柏智
     * @Date 22:44 2024/3/3
     * @Param shaneEssay
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="通过ID编辑文章", notes="通过ID编辑文章")
    @PostMapping(value = ApiMapping.UPDATE_ONE_BY_ID)
    public Result<SuccessedOutVO> updateOneById(
            @RequestBody ShaneEssay shaneEssay
    ) {
        SuccessedOutVO successedOutVO = shaneEssayService.updateOneById(shaneEssay);
        return Result.OK(successedOutVO);
    }
    
    /**
     * 通过关键字模糊查询文章列表
     *
     * @Author 闻柏智
     * @Date 16:18 2024/3/2
     * @Param pageInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.PageEssayOutVO>
     **/
    @ApiOperation(value="通过关键字模糊查询文章列表", notes="通过关键字模糊查询文章列表")
    @GetMapping(value = ApiMapping.PAGE_BY_CONTENT)
    public Result<PageEssayOutVO> pageByContent(PageInVO pageInVO) {
        List<PageEssayOutVO> pageEssayOutVOList = shaneEssayService.pageByContent(pageInVO);
        return Result.OK(pageEssayOutVOList);
    }

    /**
     * 我发布过的文章
     *
     * @Author 闻柏智
     * @Date 21:34 2024/3/3
     * @Param
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.entity.ShaneEssay>
     **/
    @ApiOperation(value="我发布过的文章", notes="我发布过的文章")
    @GetMapping(value = ApiMapping.MY_POSTED)
    public Result<ShaneEssay> myPosted() {
        List<ShaneEssay> shaneEssayList = shaneEssayService.myPosted();
        return Result.OK(shaneEssayList);
    }

    /**
     * 我收藏的文章
     *
     * @Author 闻柏智
     * @Date 14:36 2024/3/4
     * @Param
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.entity.ShaneEssay>
     **/
    @ApiOperation(value="我收藏的文章", notes="我收藏的文章")
    @GetMapping(value = ApiMapping.MY_COLLECTED)
    public Result<ShaneEssay> myCollected() {
        List<ShaneEssay> shaneEssayList = shaneEssayService.myCollected();
        return Result.OK(shaneEssayList);
    }

    /**
     * 通过文章ID列表查询这些文章的标签列表
     *
     * @Author 闻柏智
     * @Date 15:42 2024/3/4
     * @Param idListStr
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.EssayLabelOutVO>>
     **/
    @ApiOperation(value="通过文章ID列表查询这些文章的标签列表", notes="通过文章ID列表查询这些文章的标签列表")
    @GetMapping(value = ApiMapping.GET_ESSAY_LABEL_LIST_BY_ESSAY_ID_LIST)
    public Result<List<EssayLabelOutVO>> getEssayLabelListByEssayIdList(@RequestParam("idListStr") @ApiParam("多个id用','分割") String idListStr) {
        List<EssayLabelOutVO> EssayLabelOutVOList = shaneEssayService.getEssayLabelListByEssayIdList(idListStr);
        return Result.OK(EssayLabelOutVOList);
    }

    /**
     * 通过文章ID查询单个文章的标签
     *
     * @Author 闻柏智
     * @Date 15:43 2024/3/4
     * @Param essayId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.EssayLabelOutVO>
     **/
    @ApiOperation(value="通过文章ID查询单个文章的标签", notes="通过文章ID查询单个文章的标签")
    @GetMapping(value = ApiMapping.GET_ESSAY_LABEL_BY_ESSAY_ID)
    public Result<EssayLabelOutVO> getEssayLabelByEssayId(@RequestParam("essayId") @ApiParam("文章ID") Long essayId) {
        EssayLabelOutVO EssayLabelOutVO = shaneEssayService.getEssayLabelByEssayId(essayId);
        return Result.OK(EssayLabelOutVO);
    }

    /**
     * 通过关键字查询文章列表的元素数量和分页个数
     *
     * @Author 闻柏智
     * @Date 16:01 2024/3/4
     * @Param pageInVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.CountAndPageOutVO>
     **/
    @ApiOperation(value="通过关键字查询文章列表的元素数量和分页个数", notes="通过关键字查询文章列表的元素数量和分页个数")
    @GetMapping(value = ApiMapping.COUNT_AND_PAGE_BY_CONTENT)
    public Result<CountAndPageOutVO> countAndPageByContent(PageInVO pageInVO ) {

        CountAndPageOutVO successedOutVO = shaneEssayService.countAndPageByContent(pageInVO);

        return Result.OK(successedOutVO);
    }

    /**
     * 删除一个文章-通过ID
     *
     * @Author 闻柏智
     * @Date 16:15 2024/3/4
     * @Param idVO
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="删除一个文章-通过ID", notes="删除一个文章-通过ID")
    @PostMapping(value = ApiMapping.DELETE_ONE_ESSAY_BY_ID)
    public Result<SuccessedOutVO> deleteOneEssayById(@RequestBody IdVO idVO) {

        SuccessedOutVO successedOutVO = shaneEssayService.deleteOneEssayById(idVO);

        return Result.OK(successedOutVO);
    }


    /**
     * 用户点赞文章，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 21:23 2023/10/24
     * @Param essayUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户点赞文章", notes="用户点赞文章")
    @PostMapping(value = ApiMapping.INSERT_ONE_ESSAY_LIKES)
    public Result<String> insertOneEssayLikes(@RequestBody EssayUserRelVO essayUserRelVO) {

        String succeed = shaneLikesEssayService.insertOneEssayLikes(essayUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消点赞文章，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 21:28 2023/10/24
     * @Param essayUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消点赞文章", notes="用户取消点赞文章")
    @PostMapping(value = ApiMapping.DELETE_ONE_ESSAY_LIKES)
    public Result<String> deleteOneAnswerLikes(@RequestBody EssayUserRelVO essayUserRelVO) {

        String succeed = shaneLikesEssayService.deleteOneEssayLikes(essayUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户收藏文章，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 21:34 2023/10/24
     * @Param essayUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户收藏文章", notes="用户收藏文章")
    @PostMapping(value = ApiMapping.INSERT_ONE_ESSAY_COLLECT)
    public Result<String> insertOneEssayCollect(@RequestBody EssayUserRelVO essayUserRelVO) {

        String succeed = shaneCollectEssayService.insertOneEssayCollect(essayUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消收藏文章，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 21:38 2023/10/24
     * @Param essayUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消收藏文章", notes="用户取消收藏文章")
    @PostMapping(value = ApiMapping.DELETE_ONE_ESSAY_COLLECT)
    public Result<String> deleteOneEssayCollect(@RequestBody EssayUserRelVO essayUserRelVO) {

        String succeed = shaneCollectEssayService.deleteOneEssayCollect(essayUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户反对文章，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 21:42 2023/10/24
     * @Param essayUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户反对文章", notes="用户反对文章")
    @PostMapping(value = ApiMapping.INSERT_ONE_ESSAY_AGAINST)
    public Result<String> insertOneEssayAgainst(@RequestBody EssayUserRelVO essayUserRelVO) {

        String succeed = shaneAgainstEssayService.insertOneEssayAgainst(essayUserRelVO);

        return Result.OK(succeed);
    }

    /**
     * 用户取消反对文章，只需要answerId即可，userId自动分配为当前用户
     *
     * @Author 闻柏智
     * @Date 21:48 2023/10/24
     * @Param essayUserRelVO
     * @return com.baizhi.shane.common.base.Result<java.lang.String>
     **/
    @ApiOperation(value="用户取消反对文章", notes="用户取消反对文章")
    @PostMapping(value = ApiMapping.DELETE_ONE_ESSAY_AGAINST)
    public Result<String> deleteOneEssayAgainst(@RequestBody EssayUserRelVO essayUserRelVO) {

        String succeed = shaneAgainstEssayService.deleteOneEssayAgainst(essayUserRelVO);

        return Result.OK(succeed);
    }

    @ApiOperation(value="通过文章ID列表查询这些文章的点赞数量", notes="通过文章ID列表查询这些文章的点赞数量")
    @PostMapping(value = ApiMapping.GET_ESSAY_LIKE_COUNT_BY_ESSAY_ID_LIST)
    public Result<List<CountVO>> getEssayLikeCountByEssayIdList(@RequestBody List<Long> essayIdList ) {
        List<CountVO> countVOList = this.shaneEssayService.getEssayLikeCountByEssayIdList(essayIdList);
        return Result.OK(countVOList);
    }

    @ApiOperation(value="通过文章ID查询单个文章的点赞数量", notes="通过文章ID查询单个文章的点赞数量")
    @GetMapping(value = ApiMapping.GET_ONE_ESSAY_LIKE_COUNT_BY_ESSAY_ID)
    public Result<CountVO> getOneEssayLikeCountByEssayId(Long essayId ) {
        CountVO countVO = this.shaneEssayService.getOneEssayLikeCountByEssayId(essayId);

        return Result.OK(countVO);
    }

    @ApiOperation(value="通过文章ID列表查询这些文章的反对数量", notes="通过文章ID列表查询这些文章的反对数量")
    @PostMapping(value = ApiMapping.GET_ESSAY_AGAINST_COUNT_BY_ESSAY_ID_LIST)
    public Result<List<CountVO>> getEssayAgainstCountByEssayIdList(@RequestBody List<Long> essayIdList ) {
        List<CountVO> countVOList = this.shaneEssayService.getEssayAgainstCountByEssayIdList(essayIdList);
        return Result.OK(countVOList);
    }

    @ApiOperation(value="通过文章ID查询单个文章的反对数量", notes="通过文章ID查询单个文章的反对数量")
    @GetMapping(value = ApiMapping.GET_ONE_ESSAY_AGAINST_COUNT_BY_ESSAY_ID)
    public Result<CountVO> getOneEssayAgainstCountByEssayId(Long essayId ) {
        CountVO countVO = this.shaneEssayService.getOneEssayAgainstCountByEssayId(essayId);

        return Result.OK(countVO);
    }

    @ApiOperation(value="通过文章ID列表查询这些文章的收藏数量", notes="通过文章ID列表查询这些文章的收藏数量")
    @PostMapping(value = ApiMapping.GET_ESSAY_COLLECT_COUNT_BY_ESSAY_ID_LIST)
    public Result<List<CountVO>> getEssayCollectCountByEssayIdList(@RequestBody List<Long> essayIdList ) {
        List<CountVO> countVOList = this.shaneEssayService.getEssayCollectCountByEssayIdList(essayIdList);
        return Result.OK(countVOList);
    }

    @ApiOperation(value="通过文章ID查询单个文章的收藏数量", notes="通过文章ID查询单个文章的收藏数量")
    @GetMapping(value = ApiMapping.GET_ONE_ESSAY_COLLECT_COUNT_BY_ESSAY_ID)
    public Result<CountVO> getOneEssayCollectCountByEssayId(Long essayId ) {
        CountVO countVO = this.shaneEssayService.getOneEssayCollectCountByEssayId(essayId);
        return Result.OK(countVO);
    }

    @ApiOperation(value="通过文章ID列表查询这些文章的评论数量", notes="通过文章ID列表查询这些文章的评论数量")
    @PostMapping(value = ApiMapping.GET_ESSAY_COMMENT_COUNT_BY_ESSAY_ID_LIST)
    public Result<List<CountVO>> getEssayCommentCountByEssayIdList(@RequestBody List<Long> essayIdList ) {
        List<CountVO> countVOList = this.shaneEssayService.getEssayCommentCountByEssayIdList(essayIdList);
        return Result.OK(countVOList);
    }

    @ApiOperation(value="通过文章ID列表查询这些文章的评论数量", notes="通过文章ID列表查询这些文章的评论数量")
    @GetMapping(value = ApiMapping.GET_ONE_ESSAY_COMMENT_COUNT_BY_ESSAY_ID)
    public Result<CountVO> getOneEssayCommentCountByEssayId(Long essayId ) {
        CountVO countVO = this.shaneEssayService.getOneEssayCommentCountByEssayId(essayId);
        return Result.OK(countVO);
    }

    /**
     * 获取指定文章下所有的评论
     *
     * @Author 闻柏智
     * @Date 16:18 2024/2/28
     * @Param essayId
     * @return com.baizhi.shane.common.base.Result<java.util.List<com.baizhi.shane.shane.vo.CommentEssayVO>>
     **/
    @ApiOperation(value="获取指定文章下所有的评论", notes="获取指定文章下所有的评论")
    @GetMapping(value = ApiMapping.GET_ALL_COMMENT_BY_ESSAY_ID)
    public Result<List<CommentEssayVO>> getAllCommentByEssayId(@RequestParam Long essayId) {
        List<CommentEssayVO> commentEssayVOList = shaneCommentEssayService.getAllCommentByEssayId(essayId);
        return Result.OK(commentEssayVOList);
    }

    /**
     * 新增一个评论
     *
     * @Author 闻柏智
     * @Date 16:22 2024/2/28
     * @Param shaneCommentEssay
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.sys.vo.SuccessedOutVO>
     **/
    @ApiOperation(value="新增一个评论", notes="新增一个评论")
    @PostMapping(value = ApiMapping.INSERT_ONE_COMMENT)
    public Result<SuccessedOutVO> insertOneComment(@RequestBody ShaneCommentEssay shaneCommentEssay) {
        SuccessedOutVO successedOutVO = shaneCommentEssayService.insertOneComment(shaneCommentEssay);
        return Result.OK(successedOutVO);
    }

    /**
     * 通过ID查询单个文章信息
     *
     * @Author 闻柏智
     * @Date 16:20 2024/2/29
     * @Param essayId
     * @return com.baizhi.shane.common.base.Result<com.baizhi.shane.shane.vo.GetOneEssayOutVO>
     **/
    @ApiOperation(value="通过ID查询单个文章信息", notes="通过ID查询单个文章信息")
    @GetMapping(value = ApiMapping.GET_ONE_ESSAY_BY_ID)
    public Result<GetOneEssayOutVO> getOneEssayById(@RequestParam("essayId") @ApiParam("文章ID") Long essayId) {
        GetOneEssayOutVO getOneEssayOutVO = this.shaneEssayService.getOneEssayById(essayId);

        return Result.OK(getOneEssayOutVO);
    }
}
